<?php
class Documents extends Public_Controller
{
	function __construct()
	{
		parent::__construct();
	}
	
	function index(){
		$data['categories'] = new Category();
		$data['categories']->where("module = 'documents' and parents != 0")->order_by('id','desc')->get();
		$this->template->build("document_index",$data);
	}
	
	function inc_home(){
		$data['documents'] = new Document();
		$data['documents']->where("start_date <= date(sysdate()) and (end_date >= date(sysdate()) or end_date = date('0000-00-00')) and status = 'approve'")->order_by('id','desc')->limit(5)->get();
		$this->load->view('inc_home',$data);
	}
	
	function download($id){
		$document = new Document($id);
		$document->counter();
		$this->load->helper('download');
		$data = file_get_contents($document->file);
		$name = basename($document->file);
		force_download($name, $data); 
	}
}
?>